package ru.eas.tetris;

import java.awt.Color;
import java.util.Random;

import ru.eas.tetris.tetromino.RotatableTetromino;
import ru.eas.tetris.tetromino.SquareTetromino;
import ru.eas.tetris.tetromino.StraightTetromino;
import ru.eas.tetris.tetromino.TTetromino;

/**
 * @author aesipov
 */
public class FigureGenerator
{
    private static final int     TETROMINO_COUNT = 3;
    public static final int      RGB_DEVIDER     = 4;
    public static final int      RGB_STEP        = 256 / RGB_DEVIDER;
    private Random               random          = new Random();

    public Figure next()
    {
        return new Figure(getTetromino(), getColor());
    }

    private Color getColor()
    {
        int i = 1;
        int r = (i + random.nextInt(RGB_DEVIDER - i)) * RGB_STEP;
        int g = (i + random.nextInt(RGB_DEVIDER - i)) * RGB_STEP;
        int b = (i + random.nextInt(RGB_DEVIDER - i)) * RGB_STEP;
        return new Color(r, g, b);
    }

    public RotatableTetromino getTetromino()
    {
        switch (random.nextInt(TETROMINO_COUNT))
        {
            case 0:
                return new StraightTetromino();
            case 1:
                return new SquareTetromino();
            case 2:
                return new TTetromino();
            default:
                throw new IllegalStateException();
        }
    }
}
